/*
 * *****************************************************************************
 * Copyright (C) 2014-2024 Dennis Sheirer
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>
 * ****************************************************************************
 */

// Generated by jextract

package io.github.dsheirer.source.tuner.sdrplay.api.v3_07;

import java.lang.foreign.*;
import java.util.function.*;

import static java.lang.foreign.ValueLayout.*;
import static java.lang.foreign.MemoryLayout.PathElement.*;

/**
 * {@snippet lang=c :
 * struct {
 *     sdrplay_api_Bw_MHzT bwType;
 *     sdrplay_api_If_kHzT ifType;
 *     sdrplay_api_LoModeT loMode;
 *     sdrplay_api_GainT gain;
 *     sdrplay_api_RfFreqT rfFreq;
 *     sdrplay_api_DcOffsetTunerT dcOffsetTuner;
 * }
 * }
 */
public class sdrplay_api_TunerParamsT {

    sdrplay_api_TunerParamsT() {
        // Should not be called directly
    }

    private static final GroupLayout $LAYOUT = MemoryLayout.structLayout(
        sdrplay_api_h.C_INT.withName("bwType"),
        sdrplay_api_h.C_INT.withName("ifType"),
        sdrplay_api_h.C_INT.withName("loMode"),
        sdrplay_api_GainT.layout().withName("gain"),
        MemoryLayout.paddingLayout(4),
        sdrplay_api_RfFreqT.layout().withName("rfFreq"),
        sdrplay_api_DcOffsetTunerT.layout().withName("dcOffsetTuner"),
        MemoryLayout.paddingLayout(4)
    ).withName("$anon$83:9");

    /**
     * The layout of this struct
     */
    public static final GroupLayout layout() {
        return $LAYOUT;
    }

    private static final OfInt bwType$LAYOUT = (OfInt)$LAYOUT.select(groupElement("bwType"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * sdrplay_api_Bw_MHzT bwType
     * }
     */
    public static final OfInt bwType$layout() {
        return bwType$LAYOUT;
    }

    private static final long bwType$OFFSET = 0;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * sdrplay_api_Bw_MHzT bwType
     * }
     */
    public static final long bwType$offset() {
        return bwType$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * sdrplay_api_Bw_MHzT bwType
     * }
     */
    public static int bwType(MemorySegment struct) {
        return struct.get(bwType$LAYOUT, bwType$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * sdrplay_api_Bw_MHzT bwType
     * }
     */
    public static void bwType(MemorySegment struct, int fieldValue) {
        struct.set(bwType$LAYOUT, bwType$OFFSET, fieldValue);
    }

    private static final OfInt ifType$LAYOUT = (OfInt)$LAYOUT.select(groupElement("ifType"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * sdrplay_api_If_kHzT ifType
     * }
     */
    public static final OfInt ifType$layout() {
        return ifType$LAYOUT;
    }

    private static final long ifType$OFFSET = 4;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * sdrplay_api_If_kHzT ifType
     * }
     */
    public static final long ifType$offset() {
        return ifType$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * sdrplay_api_If_kHzT ifType
     * }
     */
    public static int ifType(MemorySegment struct) {
        return struct.get(ifType$LAYOUT, ifType$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * sdrplay_api_If_kHzT ifType
     * }
     */
    public static void ifType(MemorySegment struct, int fieldValue) {
        struct.set(ifType$LAYOUT, ifType$OFFSET, fieldValue);
    }

    private static final OfInt loMode$LAYOUT = (OfInt)$LAYOUT.select(groupElement("loMode"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * sdrplay_api_LoModeT loMode
     * }
     */
    public static final OfInt loMode$layout() {
        return loMode$LAYOUT;
    }

    private static final long loMode$OFFSET = 8;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * sdrplay_api_LoModeT loMode
     * }
     */
    public static final long loMode$offset() {
        return loMode$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * sdrplay_api_LoModeT loMode
     * }
     */
    public static int loMode(MemorySegment struct) {
        return struct.get(loMode$LAYOUT, loMode$OFFSET);
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * sdrplay_api_LoModeT loMode
     * }
     */
    public static void loMode(MemorySegment struct, int fieldValue) {
        struct.set(loMode$LAYOUT, loMode$OFFSET, fieldValue);
    }

    private static final GroupLayout gain$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("gain"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * sdrplay_api_GainT gain
     * }
     */
    public static final GroupLayout gain$layout() {
        return gain$LAYOUT;
    }

    private static final long gain$OFFSET = 12;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * sdrplay_api_GainT gain
     * }
     */
    public static final long gain$offset() {
        return gain$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * sdrplay_api_GainT gain
     * }
     */
    public static MemorySegment gain(MemorySegment struct) {
        return struct.asSlice(gain$OFFSET, gain$LAYOUT.byteSize());
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * sdrplay_api_GainT gain
     * }
     */
    public static void gain(MemorySegment struct, MemorySegment fieldValue) {
        MemorySegment.copy(fieldValue, 0L, struct, gain$OFFSET, gain$LAYOUT.byteSize());
    }

    private static final GroupLayout rfFreq$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("rfFreq"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * sdrplay_api_RfFreqT rfFreq
     * }
     */
    public static final GroupLayout rfFreq$layout() {
        return rfFreq$LAYOUT;
    }

    private static final long rfFreq$OFFSET = 40;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * sdrplay_api_RfFreqT rfFreq
     * }
     */
    public static final long rfFreq$offset() {
        return rfFreq$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * sdrplay_api_RfFreqT rfFreq
     * }
     */
    public static MemorySegment rfFreq(MemorySegment struct) {
        return struct.asSlice(rfFreq$OFFSET, rfFreq$LAYOUT.byteSize());
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * sdrplay_api_RfFreqT rfFreq
     * }
     */
    public static void rfFreq(MemorySegment struct, MemorySegment fieldValue) {
        MemorySegment.copy(fieldValue, 0L, struct, rfFreq$OFFSET, rfFreq$LAYOUT.byteSize());
    }

    private static final GroupLayout dcOffsetTuner$LAYOUT = (GroupLayout)$LAYOUT.select(groupElement("dcOffsetTuner"));

    /**
     * Layout for field:
     * {@snippet lang=c :
     * sdrplay_api_DcOffsetTunerT dcOffsetTuner
     * }
     */
    public static final GroupLayout dcOffsetTuner$layout() {
        return dcOffsetTuner$LAYOUT;
    }

    private static final long dcOffsetTuner$OFFSET = 56;

    /**
     * Offset for field:
     * {@snippet lang=c :
     * sdrplay_api_DcOffsetTunerT dcOffsetTuner
     * }
     */
    public static final long dcOffsetTuner$offset() {
        return dcOffsetTuner$OFFSET;
    }

    /**
     * Getter for field:
     * {@snippet lang=c :
     * sdrplay_api_DcOffsetTunerT dcOffsetTuner
     * }
     */
    public static MemorySegment dcOffsetTuner(MemorySegment struct) {
        return struct.asSlice(dcOffsetTuner$OFFSET, dcOffsetTuner$LAYOUT.byteSize());
    }

    /**
     * Setter for field:
     * {@snippet lang=c :
     * sdrplay_api_DcOffsetTunerT dcOffsetTuner
     * }
     */
    public static void dcOffsetTuner(MemorySegment struct, MemorySegment fieldValue) {
        MemorySegment.copy(fieldValue, 0L, struct, dcOffsetTuner$OFFSET, dcOffsetTuner$LAYOUT.byteSize());
    }

    /**
     * Obtains a slice of {@code arrayParam} which selects the array element at {@code index}.
     * The returned segment has address {@code arrayParam.address() + index * layout().byteSize()}
     */
    public static MemorySegment asSlice(MemorySegment array, long index) {
        return array.asSlice(layout().byteSize() * index);
    }

    /**
     * The size (in bytes) of this struct
     */
    public static long sizeof() { return layout().byteSize(); }

    /**
     * Allocate a segment of size {@code layout().byteSize()} using {@code allocator}
     */
    public static MemorySegment allocate(SegmentAllocator allocator) {
        return allocator.allocate(layout());
    }

    /**
     * Allocate an array of size {@code elementCount} using {@code allocator}.
     * The returned segment has size {@code elementCount * layout().byteSize()}.
     */
    public static MemorySegment allocateArray(long elementCount, SegmentAllocator allocator) {
        return allocator.allocate(MemoryLayout.sequenceLayout(elementCount, layout()));
    }

    /**
     * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
     * The returned segment has size {@code layout().byteSize()}
     */
    public static MemorySegment reinterpret(MemorySegment addr, Arena arena, Consumer<MemorySegment> cleanup) {
        return reinterpret(addr, 1, arena, cleanup);
    }

    /**
     * Reinterprets {@code addr} using target {@code arena} and {@code cleanupAction} (if any).
     * The returned segment has size {@code elementCount * layout().byteSize()}
     */
    public static MemorySegment reinterpret(MemorySegment addr, long elementCount, Arena arena, Consumer<MemorySegment> cleanup) {
        return addr.reinterpret(layout().byteSize() * elementCount, arena, cleanup);
    }
}

